package org.firefly.fx.service.websocket;

import javax.annotation.Resource;

import org.firefly.fx.constants.ConfigInfo;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.HandshakeInterceptor;

/**
 * websocket 路径配置页面
 * @author firefly
 */
@Configuration
@EnableWebMvc
@EnableWebSocket
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {
	@Resource(name="systemWebSocketHandler") private WebSocketHandler websocketHandler;
	@Resource(name="webSocketHandshakeInterceptor") private HandshakeInterceptor handshakeInterceptor;
	
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(websocketHandler, ConfigInfo.URL_WEBSOCKET_CONNECT)
        		.addInterceptors(handshakeInterceptor)
                .withSockJS();
    }

}
